﻿using ReflectionStudio.Core.Events;
using System;
using System.ComponentModel;
using System.Data;
using System.Windows;
using WPFExcelReport.Helpers;
namespace WPFExcelReport
{
    public partial class TLSVA09 
    {

        public TLSVA09()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return; 
            MV = new VVAFARBEN();
            DataContext = MV;  
            InitializeComponent();  
        }
        public override void vwMaster_CurrentChanged(object sender, EventArgs e)
        {
            base.vwMaster_CurrentChanged(sender, e);
            dwVF = dwMaster;
            if (dwMaster != null)
            {
                FARBGRP = dwMaster["VAFFARBGRP"].ToString();
                PRART = dwMaster["VAAARTST"].ToString().PadRight(1) + TMV.VAFPART + TMV.VAFPVAR.PadRight(3) + TMV.VAFFFARBE + TMV.VAFBESCHICH + TMV.VAFDESS + TMV.VAFCOLORIT + TMV.VAFPGROE;
                KEY = dwMaster["VAFKOLL"].ToString() + dwMaster["VAFART"].ToString() + dwMaster["VAFFARBE"].ToString();
                TXTISIND = KEY.PadRight(60);
            }
            else
            {
                PRART = "";
                KEY = "";
                TXTISIND = "";
            }
        }
        public override void OnLSARTChg(string value)
        { 
            TMV.IsMoreThanOne = false;
            if (value.Length < 32)
                return;
            TBMain.Clear();
            if (value.Trim().Length == 0)
            {
                Tracer.Error("VA10为空","哪里有问题");
                return;
            }
            dwData = TBMain.NewRow();
            dwData["VAFMANDANT"] = app.Mandant;
            dwData["VAFPART"] = value.Substring(0, 20);
            dwData["VAFPVAR"] = value.Substring(20, 2);
            dwData["VAFFFARBE"] = Helper.Right(value, 10); 
            SResult = TMV.QVAF08(dwData);
            MergeData(SResult, true);
            if (TBMain.Rows.Count > 1)
            {
                TMV.IsMoreThanOne = true;
            }
            base.OnLSARTChg(value);
        }  

        public override void EditCommand(object sender, RoutedEventArgs e)
        {
            if (IsEdit)
            {
                OnVARTChg(KEY);
            }
            else
            {  
                VICC_WFEVENTS.SVWF.VA09(this.RUNID,KEY);
            }
            base.EditCommand(sender, e);
        }

    }
}
